package com.mutual.assistance.system.api;

import com.mutual.assistance.response.R;
import com.mutual.assistance.system.model.dto.DictionaryDTO;
import com.mutual.assistance.system.service.DictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;


@Slf4j
@RestController
@Api(tags = "数据字典接口")
public class DictionaryController {

    @Resource
    private DictionaryService dictionaryService;

    @GetMapping("/dictionary/all")
    @ApiOperation("获取所有数据字典")
    public R<List<DictionaryDTO>> queryAll() {
        List<DictionaryDTO> list = dictionaryService.queryAll();
        return R.success(list, "获取成功");
    }

    @GetMapping("/dictionary/code/{code}")
    @ApiOperation("根据编码获取数据字典")
    public R<DictionaryDTO> getByCode(
            @NotBlank(message = "code不能为空") @PathVariable String code
    ) {
        DictionaryDTO dto = dictionaryService.getByCode(code);
        return R.success(dto, "获取成功");
    }
}
